home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Mark Pilgrim / Lose Your Marbles! 1.0 / source / Shell ƒ / help.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-30  |  21.0 KB  |  823 lines  |  [TEXT/KAHL]

  1. /**********************************************************************\
  2.  
  3. File:        help.c
  4.  
  5. Purpose:    This module handles displaying the different help windows.
  6.  
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or
  10. (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program in a file named "GNU General Public License".
  19. If not, write to the Free Software Foundation, 675 Mass Ave,
  20. Cambridge, MA 02139, USA.
  21.  
  22. \**********************************************************************/
  23.  
  24. #include "help.h"
  25. #include "environment.h"
  26. #include "util.h"
  27. #include "buttons.h"
  28. #include "timing.h"
  29. #include "program globals.h"
  30.  
  31. #define DEAD_SPACE_TOP        10
  32. #define DEAD_SPACE_LEFT        10
  33. #define DEAD_SPACE_BOTTOM    27
  34. #define DEAD_SPACE_RIGHT    10
  35. #define    TEXT_RECT_WIDTH        405
  36. #define    TEXT_RECT_HEIGHT    250
  37. #define    BUTTON_WIDTH        60
  38. #define    BUTTON_HEIGHT        60
  39. #define    XREF_DEAD_SPACE_TOP    5
  40. #define XREF_TEXT_WIDTH        46
  41. #define    XREF_WIDTH            70
  42. #define    XREF_HEIGHT            17
  43. #define    XREF_GAP            5
  44.  
  45. #define MAX_MAIN_TOPICS        4
  46. #define    MAX_SUB_TOPICS        5
  47.  
  48. #define    MAX_XREFS            4
  49.  
  50. #define MAIN_TOPIC_ID        600
  51. #define FIRST_SUB_TOPIC_ID    610
  52.  
  53. #define theWindowWidth (boundsRect.right-boundsRect.left)
  54. #define theWindowHeight (boundsRect.bottom-boundsRect.top)
  55. #define CorrectTime 1
  56. #define SCROLL_BOX_SIZE        20
  57.  
  58. typedef unsigned char    **CharHandle;
  59.  
  60. typedef struct
  61. {
  62.     long            offset;
  63.     short            lineHeight;
  64.     short            fontDescent;
  65.     short            fontNum;
  66.     unsigned char    fontStyle;
  67.     unsigned char    unused1;
  68.     short            fontSize;
  69.     short            unused2;
  70.     short            unused3;
  71.     short            unused4;
  72. } OneStyle;
  73.  
  74. typedef struct
  75. {
  76.     short        numStyles;
  77.     OneStyle    theStyle[31];
  78. } StylRec, *StylPtr, **StylHandle;
  79.  
  80. enum
  81. {
  82.     kLeft=0,
  83.     kCenter
  84. };
  85.  
  86. short            gNumMainTopics;
  87. short            gNumSubTopics[MAX_MAIN_TOPICS];
  88. short            gNumXRefs[MAX_MAIN_TOPICS][MAX_SUB_TOPICS];
  89.  
  90. CIconHandle        gMainTopicIconColor[MAX_MAIN_TOPICS];
  91. Handle            gMainTopicIconBW[MAX_MAIN_TOPICS];
  92. Str31            gMainTopicTitle[MAX_MAIN_TOPICS];
  93. Rect            gMainTopicRect[MAX_MAIN_TOPICS];
  94.  
  95. CIconHandle        gSubTopicIconColor[MAX_MAIN_TOPICS][MAX_SUB_TOPICS];
  96. Handle            gSubTopicIconBW[MAX_MAIN_TOPICS][MAX_SUB_TOPICS];
  97. Str31            gSubTopicTitle[MAX_MAIN_TOPICS][MAX_SUB_TOPICS];
  98. Rect            gSubTopicRect[MAX_MAIN_TOPICS][MAX_SUB_TOPICS];
  99. short            gSubTopicID[MAX_MAIN_TOPICS][MAX_SUB_TOPICS];
  100.  
  101. short            gXRefIndex[MAX_MAIN_TOPICS][MAX_SUB_TOPICS][MAX_XREFS];
  102. Rect            gXRefRect[MAX_XREFS];
  103.  
  104. short            gStickyTopic;
  105. short            gStickySubTopic;
  106.  
  107. short            gMainTopicShowing;        /* saved in prefs file */
  108. short            gSubTopicShowing;        /* saved in prefs file */
  109.  
  110. Rect            gTextRect;
  111. CharHandle        gTheText;
  112. StylHandle        gTheStyle;
  113.  
  114. /*-----------------------------------------------------------------------------------*/
  115. /* internal stuff for help.c                                                         */
  116.  
  117. void SetupTheHelpWindow(WindowDataHandle theData);
  118. void ShutdownTheHelpWindow(WindowDataHandle theData);
  119. void InitializeTheHelpWindow(WindowDataHandle theData);
  120. void OpenTheHelpWindow(WindowDataHandle theData);
  121. void KeyPressedInHelpWindow(WindowDataHandle theData, unsigned char keyPressed);
  122. void MouseClickedInHelpWindow(WindowDataHandle theData, Point mouseLoc);
  123. void DrawTheHelpWindow(short theDepth);
  124. void DrawTheText(CharHandle theText, StylHandle theStyleHandle, short theJust,
  125.     short theMode, Rect theRect);
  126. void DrawTheShadowBox(Rect theRect);
  127. short ParseRawTitle(Str255 theTitle, short *xRef, short *numXRefs);
  128. void GoToPage(WindowDataHandle theData, short mainTopic, short subTopic,
  129.     Boolean updateNow);
  130. void PushInSubTopic(WindowDataHandle theData);
  131. void PullOutSubTopic(WindowDataHandle theData, short mainTopic);
  132. void HighlightSubTopic(WindowDataHandle theData, short mainTopic, short subTopic,
  133.     Boolean isHighlighted);
  134. void GetTextResources(short mainTopic, short subTopic);
  135. void DisposeTextResources(void);
  136. void FullScrollRight(GrafPtr sourceGrafPtr, GrafPtr destGrafPtr, Rect boundsRect);
  137. void CalculateXRefInfo(short index, short *mainTopic, short *subTopic, Str255 name);
  138.  
  139.  
  140. short HelpWindowDispatch(WindowDataHandle theData, short theMessage, unsigned long misc)
  141. {
  142.     unsigned char    theChar;
  143.     Point            thePoint;
  144.     short            theDepth;
  145.     
  146.     switch (theMessage)
  147.     {
  148.         case kUpdate:
  149.             theDepth=misc&0x7fff;
  150.             DrawTheHelpWindow(theDepth);
  151.             return kSuccess;
  152.             break;
  153.         case kKeydown:
  154.             theChar=misc&charCodeMask;
  155.             KeyPressedInHelpWindow(theData, theChar);
  156.             return kSuccess;
  157.             break;
  158.         case kMousedown:
  159.             thePoint.h=(misc>>16)&0x7fff;
  160.             thePoint.v=misc&0x7fff;
  161.             MouseClickedInHelpWindow(theData, thePoint);
  162.             return kSuccess;
  163.             break;
  164.         case kOpen:
  165.             OpenTheHelpWindow(theData);
  166.             return kSuccess;
  167.             break;
  168.         case kInitialize:
  169.             InitializeTheHelpWindow(theData);
  170.             return kSuccess;
  171.             break;
  172.         case kStartup:
  173.             SetupTheHelpWindow(theData);
  174.             return kSuccess;
  175.             break;
  176.         case kShutdown:
  177.             ShutdownTheHelpWindow(theData);
  178.             return kSuccess;
  179.             break;
  180.     }
  181.     
  182.     return kFailure;        /* revert to default processing for all other messages */
  183. }
  184.  
  185. void SetupTheHelpWindow(WindowDataHandle theData)
  186. {
  187.     short            i,j;
  188.     unsigned char    *helpStr="\pHelp";
  189.     Handle            temp;
  190.     short            iconID;
  191.     short            centeringOffset;
  192.     
  193.     temp=GetResource('STR#', MAIN_TOPIC_ID);
  194.     gNumMainTopics=**((short**)temp);
  195.     ReleaseResource(temp);
  196.     for (i=0; i<gNumMainTopics; i++)
  197.     {
  198.         temp=GetResource('STR#', FIRST_SUB_TOPIC_ID+i);
  199.         gNumSubTopics[i]=**((short**)temp);
  200.         ReleaseResource(temp);
  201.     }
  202.     centeringOffset=DEAD_SPACE_TOP;
  203.     for (i=0; i<gNumMainTopics; i++)
  204.     {
  205.         GetIndString(gMainTopicTitle[i], MAIN_TOPIC_ID, i+1);
  206.         iconID=ParseRawTitle(gMainTopicTitle[i], 0L, 0L);
  207.         if (gHasColorQD)
  208.             gMainTopicIconColor[i]=GetCIcon(iconID);
  209.         gMainTopicIconBW[i]=GetIcon(iconID);
  210.         SetRect(&gMainTopicRect[i], DEAD_SPACE_LEFT, centeringOffset+BUTTON_HEIGHT*i,
  211.             DEAD_SPACE_LEFT+BUTTON_WIDTH, centeringOffset+BUTTON_HEIGHT*(i+1));
  212.         
  213.         for (j=0; j<gNumSubTopics[i]; j++)
  214.         {
  215.             GetIndString(gSubTopicTitle[i][j], FIRST_SUB_TOPIC_ID+i, j+1);
  216.             iconID=ParseRawTitle(gSubTopicTitle[i][j], gXRefIndex[i][j], &(gNumXRefs[i][j]));
  217.             gSubTopicID[i][j]=iconID;
  218.             if (gHasColorQD)
  219.                 gSubTopicIconColor[i][j]=GetCIcon(iconID);
  220.             gSubTopicIconBW[i][j]=GetIcon(iconID);
  221.             SetRect(&gSubTopicRect[i][j], DEAD_SPACE_LEFT+BUTTON_WIDTH*(j+1),
  222.                 centeringOffset+BUTTON_HEIGHT*i, DEAD_SPACE_LEFT+BUTTON_WIDTH*(j+2),
  223.                 centeringOffset+BUTTON_HEIGHT*(i+1));
  224.         }
  225.     }
  226.     
  227.     for (i=0; i<MAX_XREFS; i++)
  228.     {
  229.         SetRect(&gXRefRect[i], XREF_TEXT_WIDTH+DEAD_SPACE_LEFT+BUTTON_WIDTH+DEAD_SPACE_LEFT+
  230.             i*(XREF_WIDTH+XREF_GAP), DEAD_SPACE_TOP+TEXT_RECT_HEIGHT+XREF_DEAD_SPACE_TOP,
  231.             XREF_TEXT_WIDTH+DEAD_SPACE_LEFT+BUTTON_WIDTH+DEAD_SPACE_LEFT+
  232.             i*(XREF_WIDTH+XREF_GAP)+XREF_WIDTH, DEAD_SPACE_TOP+TEXT_RECT_HEIGHT+
  233.             XREF_DEAD_SPACE_TOP+XREF_HEIGHT);
  234.     }
  235.     
  236.     gTheText=0L;
  237.     gTheStyle=0L;
  238.     GoToPage(0L, gMainTopicShowing, gSubTopicShowing, FALSE);
  239.     
  240.     SetRect(&gTextRect, DEAD_SPACE_LEFT+BUTTON_WIDTH+DEAD_SPACE_LEFT, DEAD_SPACE_TOP,
  241.         DEAD_SPACE_LEFT+BUTTON_WIDTH+DEAD_SPACE_LEFT+TEXT_RECT_WIDTH,
  242.         DEAD_SPACE_TOP+TEXT_RECT_HEIGHT);
  243.     
  244.     (**theData).maxDepth=8;
  245.     (**theData).windowWidth=DEAD_SPACE_LEFT+BUTTON_WIDTH+DEAD_SPACE_LEFT+
  246.         TEXT_RECT_WIDTH+DEAD_SPACE_RIGHT;
  247.     (**theData).windowHeight=DEAD_SPACE_TOP+TEXT_RECT_HEIGHT+DEAD_SPACE_BOTTOM;
  248.     (**theData).windowType=noGrowDocProc;    /* document-looking thing */
  249.     (**theData).hasCloseBox=TRUE;
  250.     (**theData).windowBounds.top=50;
  251.     (**theData).windowBounds.left=6;
  252.     SetIndWindowTitle(kHelp, helpStr);
  253.     
  254.     if (gIsVirgin)
  255.         OpenTheIndWindow((**theData).windowIndex);
  256. }
  257.  
  258. void ShutdownTheHelpWindow(WindowDataHandle theData)
  259. {
  260.     short            i,j;
  261.     
  262.     for (i=0; i<gNumMainTopics; i++)
  263.     {
  264.         if (gHasColorQD)
  265.             DisposeCIcon(gMainTopicIconColor[i]);
  266.         ReleaseResource(gMainTopicIconBW[i]);
  267.         
  268.         for (j=0; j<gNumSubTopics[i]; j++)
  269.         {
  270.             if (gHasColorQD)
  271.                 DisposeCIcon(gSubTopicIconColor[i][j]);
  272.             ReleaseResource(gSubTopicIconBW[i][j]);
  273.         }
  274.     }
  275.     DisposeTextResources();
  276. }
  277.  
  278. void InitializeTheHelpWindow(WindowDataHandle theData)
  279. {
  280.     (**theData).initialTopLeft.v=(**theData).windowBounds.top-9;
  281.     (**theData).initialTopLeft.h=(**theData).windowBounds.left;
  282.     gStickyTopic=-1;
  283. }
  284.  
  285. void OpenTheHelpWindow(WindowDataHandle theData)
  286. {
  287.     (**theData).offscreenNeedsUpdate=TRUE;
  288. }
  289.  
  290. void KeyPressedInHelpWindow(WindowDataHandle theData, unsigned char keyPressed)
  291. {
  292.     short            oldTopic;
  293.     
  294.     ObscureCursor();
  295.     
  296.     switch (keyPressed)
  297.     {
  298.         case 0x1d:                                        /* right arrow */
  299.             if (gStickyTopic==-1)
  300.             {
  301.                 gSubTopicShowing++;
  302.                 if (gSubTopicShowing>=gNumSubTopics[gMainTopicShowing])
  303.                 {
  304.                     gSubTopicShowing=0;
  305.                     gMainTopicShowing++;
  306.                     if (gMainTopicShowing>=gNumMainTopics)
  307.                         gMainTopicShowing=0;
  308.                 }
  309.                 GoToPage(theData, gMainTopicShowing, gSubTopicShowing, TRUE);
  310.             }
  311.             else
  312.             {
  313.                 if (gStickySubTopic!=-1)
  314.                     HighlightSubTopic(theData, gStickyTopic, gStickySubTopic, FALSE);
  315.                 gStickySubTopic++;
  316.                 if (gStickySubTopic>=gNumSubTopics[gStickyTopic])
  317.                     gStickySubTopic=0;
  318.                 HighlightSubTopic(theData, gStickyTopic, gStickySubTopic, TRUE);
  319.             }
  320.             break;
  321.         case 0x1c:                                        /* left arrow */
  322.             if (gStickyTopic==-1)
  323.             {
  324.                 gSubTopicShowing--;
  325.                 if (gSubTopicShowing<0)
  326.                 {
  327.                     gMainTopicShowing--;
  328.                     if (gMainTopicShowing<0)
  329.                         gMainTopicShowing=gNumMainTopics-1;
  330.                     gSubTopicShowing=gNumSubTopics[gMainTopicShowing]-1;
  331.                 }
  332.                 GoToPage(theData, gMainTopicShowing, gSubTopicShowing, TRUE);
  333.             }
  334.             else
  335.             {
  336.                 if (gStickySubTopic!=-1)
  337.                     HighlightSubTopic(theData, gStickyTopic, gStickySubTopic, FALSE);
  338.                 gStickySubTopic--;
  339.                 if (gStickySubTopic<0)
  340.                     gStickySubTopic=gNumSubTopics[gStickyTopic]-1;
  341.                 HighlightSubTopic(theData, gStickyTopic, gStickySubTopic, TRUE);
  342.             }
  343.             break;
  344.         case 0x1e:                                        /* up arrow */
  345.             if (gStickyTopic!=-1)
  346.             {
  347.                 oldTopic=gStickyTopic;
  348.                 PushInSubTopic(theData);
  349.                 gStickyTopic=oldTopic-1;
  350.                 if (gStickyTopic<0)
  351.                     gStickyTopic=gNumMainTopics-1;
  352.             }
  353.             else gStickyTopic=gNumMainTopics-1;
  354.             
  355.             PullOutSubTopic(theData, gStickyTopic);
  356.             break;
  357.         case 0x1f:                                        /* down arrow */
  358.             if (gStickyTopic!=-1)
  359.             {
  360.                 oldTopic=gStickyTopic;
  361.                 PushInSubTopic(theData);
  362.                 gStickyTopic=oldTopic+1;
  363.                 if (gStickyTopic>=gNumMainTopics)
  364.                     gStickyTopic=0;
  365.             }
  366.             else gStickyTopic=0;
  367.             
  368.             PullOutSubTopic(theData, gStickyTopic);
  369.             break;
  370.         case 0x1b:                                        /* escape key */
  371.             if (gStickyTopic!=-1)
  372.                 PushInSubTopic(theData);
  373.             else CloseTheWindow((ExtendedWindowDataHandle)theData);
  374.             break;
  375.         case 0x03:
  376.         case 0x0d:
  377.             if (gStickyTopic==-1)
  378.             {
  379.                 gStickyTopic=gMainTopicShowing;
  380.                 PullOutSubTopic(theData, gStickyTopic);
  381.             }
  382.             else
  383.             {
  384.                 if (gStickySubTopic!=-1)
  385.                 {
  386.                     HighlightSubTopic(theData, gStickyTopic, gStickySubTopic, FALSE);
  387.                     GoToPage(theData, gStickyTopic, gStickySubTopic, TRUE);
  388.                 }
  389.                 else PushInSubTopic(theData);
  390.             }
  391.             break;
  392.     }
  393. }
  394.  
  395. void MouseClickedInHelpWindow(WindowDataHandle theData, Point mouseLoc)
  396. {
  397.     short            newTopic;
  398.     Boolean            isColor;
  399.     short            i;
  400.     Str255            name;
  401.     short            newMain, newSub;
  402.     
  403.     isColor=((**theData).windowDepth>2);
  404.     newTopic=-1;
  405.     
  406.     for (i=0; i<gNumXRefs[gMainTopicShowing][gSubTopicShowing]; i++)
  407.     {
  408.         if (PtInRect(mouseLoc, &gXRefRect[i]))
  409.         {
  410.             CalculateXRefInfo(gXRefIndex[gMainTopicShowing][gSubTopicShowing][i],
  411.                 &newMain, &newSub, name);
  412.             
  413.             if ((newMain!=-1) && (newSub!=-1))
  414.             {
  415.                 if (Track3DButton(&gXRefRect[i], name, 0L, (**theData).windowDepth))
  416.                 {
  417.                     GoToPage(theData, newMain, newSub, TRUE);
  418.                     return;
  419.                 }
  420.             }
  421.         }
  422.     }
  423.     
  424.     for (i=0; i<gNumMainTopics; i++)
  425.     {
  426.         if (PtInRect(mouseLoc, &gMainTopicRect[i]))
  427.         {
  428.             newTopic=i;
  429.             i=gNumMainTopics;
  430.         }
  431.     }
  432.     
  433.     if (newTopic!=-1)
  434.     {
  435.         if (newTopic==gStickyTopic)
  436.             PushInSubTopic(theData);
  437.         else
  438.         {
  439.             if (gStickyTopic!=-1)
  440.                 PushInSubTopic(theData);
  441.             PullOutSubTopic(theData, newTopic);
  442.             gStickyTopic=newTopic;
  443.         }
  444.     }
  445.     
  446.     if ((gStickyTopic!=-1) && (newTopic==-1))
  447.     {
  448.         for (i=0; i<gNumSubTopics[gStickyTopic]; i++)
  449.         {
  450.             if (PtInRect(mouseLoc, &gSubTopicRect[gStickyTopic][i]))
  451.             {
  452.                 if (gStickySubTopic!=-1)
  453.                     HighlightSubTopic(theData, gStickyTopic, gStickySubTopic, FALSE);
  454.                 gStickySubTopic=-1;
  455.                 
  456.                 if (Track3DButton(&gSubTopicRect[gStickyTopic][i],
  457.                     gSubTopicTitle[gStickyTopic][i], isColor ?
  458.                     (Handle)gSubTopicIconColor[gStickyTopic][i] :
  459.                     gSubTopicIconBW[gStickyTopic][i], (**theData).windowDepth))
  460.                 {
  461.                     newTopic=i;
  462.                     i=gNumSubTopics[gStickyTopic];
  463.                 }
  464.             }
  465.         }
  466.         if (newTopic!=-1)
  467.             GoToPage(theData, gStickyTopic, newTopic, TRUE);
  468.         else
  469.             PushInSubTopic(theData);
  470.     }
  471. }
  472.  
  473. void DrawTheHelpWindow(short theDepth)
  474. {
  475.     GrafPtr            curPort;
  476.     short            i,j;
  477.     Boolean            isColor;
  478.     Rect            tempRect;
  479.     Str255            theStr;
  480.     short            dummy1, dummy2;
  481.     
  482.     isColor=(theDepth>2);
  483.     
  484.     GetPort(&curPort);
  485.     EraseRect(&(curPort->portRect));
  486.     
  487.     DrawTheShadowBox(gTextRect);
  488.     if (gTheText!=0L)
  489.     {
  490.         tempRect=gTextRect;
  491.         InsetRect(&tempRect, 8, 4);
  492.         DrawTheText(gTheText, gTheStyle, kLeft, srcOr, tempRect);
  493.     }
  494.     
  495.     for (i=0; i<gNumMainTopics; i++)
  496.     {
  497.         Draw3DButton(&gMainTopicRect[i], gMainTopicTitle[i],
  498.             isColor ? (Handle)gMainTopicIconColor[i] : gMainTopicIconBW[i],
  499.             theDepth, (i==gStickyTopic));
  500.         if (i==gStickyTopic)
  501.         {
  502.             for (j=0; j<gNumSubTopics[i]; j++)
  503.             {
  504.                 Draw3DButton(&gSubTopicRect[i][j], gSubTopicTitle[i][j],
  505.                 isColor ? (Handle)gSubTopicIconColor[i][j] : gSubTopicIconBW[i][j],
  506.                 theDepth, (j==gStickySubTopic));
  507.             }
  508.         }
  509.     }
  510.     
  511.     for (i=0; i<gNumXRefs[gMainTopicShowing][gSubTopicShowing]; i++)
  512.     {
  513.         CalculateXRefInfo(gXRefIndex[gMainTopicShowing][gSubTopicShowing][i],
  514.             &dummy1, &dummy2, theStr);
  515.         Draw3DButton(&gXRefRect[i], theStr, 0L, theDepth, FALSE);
  516.     }
  517.     if (gNumXRefs[gMainTopicShowing][gSubTopicShowing]>0)
  518.     {
  519.         MoveTo(gXRefRect[0].left-XREF_TEXT_WIDTH, gXRefRect[0].bottom-5);
  520.         TextFont(geneva);
  521.         TextSize(9);
  522.         DrawString("\pSee also:");
  523.     }
  524. }
  525.  
  526. void DrawTheText(CharHandle theText, StylHandle theStyleHandle, short theJust,
  527.     short theMode, Rect theRect)
  528. {
  529.     short            i, numStyles;
  530.     long            textPos;
  531.     long            maxOffset;
  532.     Str255            thisLine;
  533.     Boolean            notDoneYet;
  534.     unsigned char    thisChar;
  535.     short            theRow, theCol;
  536.     unsigned char    lastEnd, thisEnd;
  537.     Boolean            overRun;
  538.     
  539.     numStyles=(**theStyleHandle).numStyles;
  540.     textPos=0L;
  541.     theRow=theRect.top+(**theStyleHandle).theStyle[0].fontDescent+1;
  542.     theCol=theRect.left;
  543.     thisLine[0]=0x00;
  544.     lastEnd=0;
  545.     for (i=0; i<numStyles; i++)
  546.     {
  547.         if (i==numStyles-1)
  548.             maxOffset=GetHandleSize((Handle)theText);
  549.         else
  550.             maxOffset=(**theStyleHandle).theStyle[i+1].offset;
  551.         
  552.         TextFont((**theStyleHandle).theStyle[i].fontNum);
  553.         TextFace((**theStyleHandle).theStyle[i].fontStyle);
  554.         TextSize((**theStyleHandle).theStyle[i].fontSize);
  555.         TextMode(theMode);
  556.         
  557.         while (textPos<maxOffset)
  558.         {
  559.             notDoneYet=TRUE;
  560.             while ((textPos<maxOffset) && (notDoneYet))
  561.             {
  562.                 thisChar=thisLine[++thisLine[0]]=(*theText)[textPos++];
  563.                 notDoneYet=((thisChar!=' ') && (thisChar!=0x0d));
  564.             }
  565.             
  566.             thisEnd=thisLine[0];
  567.             overRun=(theRect.right-theCol<=StringWidth(thisLine));
  568.             
  569.             if ((overRun) || (thisChar==0x0d) || (textPos==maxOffset))
  570.             {
  571.                 if (overRun)
  572.                     thisLine[0]=lastEnd;
  573.                 if (theJust==kCenter)
  574.                     MoveTo((theRect.right-theRect.left-StringWidth(thisLine))/2+
  575.                             theCol, theRow);
  576.                 else
  577.                     MoveTo(theCol, theRow);
  578.                 theCol+=StringWidth(thisLine);
  579.                 DrawString(thisLine);
  580.                 if (overRun)
  581.                 {
  582.                     BlockMove(&thisLine[lastEnd+1], &thisLine[1], thisEnd-lastEnd+1);
  583.                     if (thisEnd>=lastEnd)
  584.                     {
  585.                         thisLine[0]=thisEnd-lastEnd-1;
  586.                         textPos--;
  587.                     }
  588.                     else
  589.                         thisEnd=thisLine[0]=0x00;
  590.                 }
  591.                 else thisLine[0]=0x00;
  592.                 if ((overRun) || (thisChar==0x0d))
  593.                 {
  594.                     theRow+=(**theStyleHandle).theStyle[i].lineHeight;
  595.                     theCol=theRect.left;
  596.                 }
  597.             }
  598.             
  599.             lastEnd=thisEnd;
  600.         }
  601.         
  602.         if (thisLine[0]!=0x00)
  603.         {
  604.             if (theJust==kCenter)
  605.                 MoveTo((theRect.right-theRect.left-StringWidth(thisLine))/2+
  606.                         theCol, theRow);
  607.             else
  608.                 MoveTo(theCol, theRow);
  609.             theCol+=StringWidth(thisLine);
  610.             DrawString(thisLine);
  611.             thisLine[0]=0x00;
  612.         }
  613.     }
  614.     TextMode(srcOr);
  615. }
  616.  
  617. void DrawTheShadowBox(Rect theRect)
  618. {
  619.     theRect.right-=2;
  620.     theRect.bottom-=2;
  621.     FrameRect(&theRect);
  622.     MoveTo(theRect.left+3, theRect.bottom+1);
  623.     Line(theRect.right-theRect.left-2, 0);
  624.     Line(0, -theRect.bottom+theRect.top+3);
  625.     MoveTo(theRect.left+3, theRect.bottom);
  626.     Line(theRect.right-theRect.left-3, 0);
  627.     Line(0, -theRect.bottom+theRect.top+4);
  628. }
  629.  
  630. short ParseRawTitle(Str255 theTitle, short *xRef, short *numXRefs)
  631. {
  632.     Str255            numStr;
  633.     long            result;
  634.     short            i,j;
  635.     Boolean            gotbullet;
  636.     Boolean            moreXRefs;
  637.     
  638.     if (xRef!=0L)
  639.     {
  640.         *numXRefs=0;
  641.         for (j=1, gotbullet=FALSE; ((j<=theTitle[0]) && (!gotbullet)); j++)
  642.             gotbullet=(theTitle[j]=='%');
  643.         if (gotbullet)
  644.         {
  645.             i=j;
  646.             do
  647.             {
  648.                 numStr[0]=0x00;
  649.                 while ((numStr[0]<=theTitle[0]-i) &&
  650.                     (((numStr[numStr[0]]=theTitle[i+(numStr[0]++)]))!=' ')) {}
  651.                 if (numStr[numStr[0]]==' ')
  652.                 {
  653.                     moreXRefs=TRUE;
  654.                     i+=numStr[0];
  655.                     numStr[0]--;
  656.                 }
  657.                 else moreXRefs=FALSE;
  658.                 StringToNum(numStr, &result);
  659.                 xRef[(*numXRefs)++]=result;
  660.             }
  661.             while (moreXRefs);
  662.             theTitle[0]=j-2;
  663.         }
  664.     }
  665.     numStr[0]=0x00;
  666.     while ((numStr[numStr[0]]=theTitle[++numStr[0]])!=' ') {}
  667.     theTitle[0]-=numStr[0];
  668.     Mymemcpy((Ptr)&theTitle[1], (Ptr)&theTitle[numStr[0]+1], theTitle[0]);
  669.     numStr[0]--;
  670.     StringToNum(numStr, &result);
  671.     return result;
  672. }
  673.  
  674. void GoToPage(WindowDataHandle theData, short mainTopic, short subTopic,
  675.     Boolean updateNow)
  676. {
  677.     DisposeTextResources();
  678.     GetTextResources(mainTopic, subTopic);
  679.     gMainTopicShowing=mainTopic;
  680.     gSubTopicShowing=subTopic;
  681.     gStickyTopic=gStickySubTopic=-1;
  682.     if (updateNow)
  683.     {
  684.         (**theData).offscreenNeedsUpdate=TRUE;
  685.         UpdateTheWindow((ExtendedWindowDataHandle)theData);
  686.     }
  687. }
  688.  
  689. void PushInSubTopic(WindowDataHandle theData)
  690. {
  691.     gStickyTopic=-1;
  692.     (**theData).offscreenNeedsUpdate=TRUE;
  693.     UpdateTheWindow((ExtendedWindowDataHandle)theData);
  694. }
  695.  
  696. void PullOutSubTopic(WindowDataHandle theData, short mainTopic)
  697. {
  698.     short            i;
  699.     short            theDepth;
  700.     Boolean            isColor;
  701.     Rect            tempRect;
  702.     
  703.     gStickySubTopic=-1;
  704.     
  705.     isColor=(theDepth=(**theData).windowDepth)>2;
  706.     
  707.     SetPortToOffscreen(theData);
  708.     for (i=0; i<gNumSubTopics[mainTopic]; i++)
  709.     {
  710.         Draw3DButton(&gSubTopicRect[mainTopic][i], gSubTopicTitle[mainTopic][i],
  711.         isColor ? (Handle)gSubTopicIconColor[mainTopic][i] :
  712.         gSubTopicIconBW[mainTopic][i], theDepth, FALSE);
  713.     }
  714.     RestorePortToScreen(theData);
  715.  
  716.     Draw3DButton(&gMainTopicRect[mainTopic], gMainTopicTitle[mainTopic],
  717.         isColor ? (Handle)gMainTopicIconColor[mainTopic] :
  718.         gMainTopicIconBW[mainTopic], theDepth, TRUE);
  719.     
  720.     tempRect=gSubTopicRect[mainTopic][0];
  721.     tempRect.right=gSubTopicRect[mainTopic][gNumSubTopics[mainTopic]-1].right;
  722.     FullScrollRight(GetOffscreenGrafPtr(theData), GetWindowGrafPtr(theData), tempRect);
  723.     
  724.     (**theData).offscreenNeedsUpdate=TRUE;
  725. }
  726.  
  727. void HighlightSubTopic(WindowDataHandle theData, short mainTopic, short subTopic,
  728.     Boolean isHighlighted)
  729. {
  730.     Draw3DButton(&gSubTopicRect[mainTopic][subTopic], gSubTopicTitle[mainTopic][subTopic],
  731.         ((**theData).windowDepth>2) ? (Handle)gSubTopicIconColor[mainTopic][subTopic] :
  732.         gSubTopicIconBW[mainTopic][subTopic], (**theData).windowDepth, isHighlighted);
  733.     
  734.     (**theData).offscreenNeedsUpdate=TRUE;
  735. }
  736.  
  737. void GetTextResources(short mainTopic, short subTopic)
  738. {
  739.     short            resID;
  740.     
  741.     DisposeTextResources();
  742.     resID=gSubTopicID[mainTopic][subTopic];
  743.     gTheText=(CharHandle)GetResource('TEXT', resID);
  744.     gTheStyle=(StylHandle)GetResource('styl', resID);
  745. }
  746.  
  747. void DisposeTextResources(void)
  748. {
  749.     if (gTheText!=0L)
  750.         ReleaseResource((Handle)gTheText);
  751.     if (gTheStyle!=0L)
  752.         ReleaseResource((Handle)gTheStyle);
  753.     gTheText=0L;
  754.     gTheStyle=0L;
  755. }
  756.  
  757. void FullScrollRight(GrafPtr sourceGrafPtr, GrafPtr destGrafPtr, Rect boundsRect)
  758. {
  759.     Rect            sourceRect, destRect, scrollRect;
  760.     short            BoxSize;
  761.     
  762.     StartTiming();
  763.     
  764.     BoxSize=SCROLL_BOX_SIZE;
  765.     
  766.     destRect=sourceRect=scrollRect=boundsRect;
  767.     destRect.right=destRect.left+BoxSize;
  768.     sourceRect.left=boundsRect.right-BoxSize;
  769.     scrollRect.right=scrollRect.left+2*BoxSize;
  770.     
  771.     CopyBits(&(sourceGrafPtr->portBits), &(destGrafPtr->portBits),
  772.         &sourceRect, &destRect, 0, 0L);
  773.     
  774.     TimeCorrection(CorrectTime);
  775.     
  776.     while (scrollRect.right<=boundsRect.right)
  777.     {
  778.         StartTiming();
  779.         sourceRect.right-=BoxSize;
  780.         sourceRect.left-=BoxSize;
  781.         ScrollTheRect(&scrollRect, BoxSize, 0, 0L);
  782.         CopyBits(&(sourceGrafPtr->portBits), &(destGrafPtr->portBits),
  783.             &sourceRect, &destRect, 0, 0L);
  784.         TimeCorrection(CorrectTime);
  785.         scrollRect.right+=BoxSize;
  786.     }
  787.     
  788.     if (scrollRect.right!=boundsRect.right)
  789.         CopyBits(&(sourceGrafPtr->portBits), &(destGrafPtr->portBits),
  790.             &boundsRect, &boundsRect, 0, 0L);
  791. }
  792.  
  793. void CalculateXRefInfo(short index, short *mainTopic, short *subTopic, Str255 name)
  794. {
  795.     short            theMain, theSub;
  796.     unsigned char    *bad="\pBad XRef!";
  797.     
  798.     theMain=gNumMainTopics-1;
  799.     theSub=gNumSubTopics[theMain]-1;
  800.     while ((theMain>=0) && (index!=gSubTopicID[theMain][theSub]))
  801.     {
  802.         theSub--;
  803.         if (theSub<0)
  804.         {
  805.             theMain--;
  806.             theSub=gNumSubTopics[theMain];
  807.         }
  808.     }
  809.     
  810.     if (theMain<0)
  811.     {
  812.         Mymemcpy((Ptr)name, (Ptr)bad, bad[0]+1);
  813.         *mainTopic=*subTopic=-1;
  814.     }
  815.     else
  816.     {
  817.         Mymemcpy((Ptr)name, (Ptr)gSubTopicTitle[theMain][theSub],
  818.             gSubTopicTitle[theMain][theSub][0]+1);
  819.         *mainTopic=theMain;
  820.         *subTopic=theSub;
  821.     }
  822. }
  823.